home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 24 / fastbios.zip / BREAKON.ASM next >
Assembly Source File  |  1985-12-24  |  8KB  |  237 lines

  1.         title  BREAKON
  2.         comment \
  3.         Function      Ctrl-Brk terminates any program
  4.         Author        Robert Wagner
  5.         Date Written  12/22/85
  6.         Remarks       Must the the last program in your AUTOEXEC.BAT
  7.                       When Ctrl-Brk is hit, does the following:
  8.                         ..makes sure you are not on the command line or
  9.                           in a resident program or executing a DOS call
  10.                           (a second Ctrl-Brk will bypass these checks).
  11.                         ..resets the keyboard
  12.                         ..discards all interrupts pending in the 8259
  13.                         ..resets 8255 and 8259 ports (61 and 21)
  14.                         ..does a BIOS break (1B) and a DOS break (23) to
  15.                           give your program's Ctrl-Brk routine a chance to do
  16.                           its thing.
  17.                           If I do not get control back, third Ctrl-Brk will
  18.                           bypass this step.
  19.                         ..restores all interrupt vectors to the values
  20.                           they had when I was made resident.  That's
  21.                           why I have to be last in the AUTOEXEC.
  22.                         ..restores screen parameters in BIOS segment
  23.                         ..clears the screen (into BACKSCRL, if present)
  24.                         ..does not flush keyboard buffer.  May help to
  25.                           indicate where it blew up.
  26.                         ..does a terminate (4C) with return code FF.
  27.         \
  28. cseg    segment
  29.         assume cs:cseg,ds:cseg,es:nothing
  30.         org   100H           ; I am .COM
  31. start   proc  far
  32.         jmp   makeres
  33. start   endp
  34.  
  35.         db    'BREAKON v1.1 Public Domain 1985 Robert Wagner, 806-763-3375'
  36. a_int09 dd    0              ; original INT 09
  37. a_int21 dd    0              ; original INT 21
  38. zero    dd    0              ; addr of interrupt vectors
  39. port21  db    0              ; initial values in ports
  40. port61  db    0
  41. in_prog db    0              ; in-progress flag
  42. a_break dw    71H,40H        ; addr of BIOS break bit
  43. a_bios  dw    49H,40H        ; addr of BIOS screen stuff
  44. BIOSwss db    30 dup(?)      ; save area for above
  45. DOSregs dw    6 dup(?)       ; save area for registers of last dos call
  46. ctrl_key     equ 29
  47. scroll_key   equ 70
  48. s_vector     equ 512
  49.  
  50.  
  51.         assume cs:cseg,ds:nothing,es:nothing
  52. int09   proc  far                   ; comes here on keystroke
  53.         sti
  54.         push  ax
  55.         in    al,60H                ; read the keycode
  56.         test  al,10000000B          ; ignore "key break"
  57.         jnz   int09x
  58.         cmp   al,ctrl_key           ; ignore Ctrl key
  59.         je    int09x
  60.         cmp   al,scroll_key         ; check for Brk
  61.         je    int09a
  62.         mov   cs:in_prog,0          ; some other key, reset in progress flag
  63. int09x: pop   ax
  64.         jmp   dword ptr cs:a_int09  ; jump to original int09
  65.  
  66. int09a: mov   ah,2                  ; check for Ctrl-Brk
  67.         int   16H
  68.         test  al,00000100B
  69.         jz    int09x
  70.         call  bomb                  ; do it
  71.         jmp   int09x
  72. int09   endp
  73.  
  74.         assume cs:cseg,ds:cseg,es:nothing
  75.  
  76. bomb    proc  near
  77.         push  ds
  78.         push  es
  79.         push  bx
  80.         mov   ax,cs
  81.         mov   ds,ax
  82.  
  83.         inc   in_prog
  84.         cmp   in_prog,3             ; third try?
  85.         je    bombc                 ; y - bypass below tests, do it
  86.         cmp   in_prog,2             ; second try?
  87.         je    bomba                 ; y - bypass some of the tests
  88.         mov   bx,sp
  89.         mov   ax,word ptr ss:[bx+12] ; get segment of interrupted task
  90.         mov   bx,cs
  91.         cmp   ax,bx                 ; compare to mine
  92.         jb    bombx                 ; lower: resident pgm or DOS, exit
  93.         cmp   ax,0F000H             ; BIOS call in progress?
  94.         jae   bombx                 ; y - exit
  95. bomba:  mov   ax,5100H              ; get psp of current task
  96.         int   21H
  97.         mov   es,bx
  98.         cmp   byte ptr es:[0],0CDH  ; look like a program?
  99.         jne   bombx
  100.         mov   ax,es
  101.         cmp   ax,es:[16H]           ; was it invoked by itself?
  102.         jne   bombc                 ; y - it's COMMAND.COM
  103.         mov   in_prog,0             ;     get out
  104. bombx:  pop   bx
  105.         pop   es
  106.         pop   ds
  107.         ret
  108.  
  109. bombc:  cld
  110.         in    al,61H                ; reset the keyboard (via 8255)
  111.         or    al,10000000B
  112.         out   61H,al
  113.         mov   al,port61             ; reset the 8255
  114.         and   al,01111111B
  115.         out   61H,al
  116.         cli
  117.         mov   al,port21             ; reset interrupts enabled (port 21)
  118.         out   21H,al
  119.         mov   cx,8
  120. bomb1:  mov   al,20H                ; cancel anything stacked in 8259
  121.         out   20H,al
  122.         loop  bomb1
  123.         sti
  124.  
  125.         cmp   in_prog,3
  126.         je    bomb2
  127.         les   di,dword ptr a_break
  128.         mov   al,80H
  129.         stosb                       ; set bios break bit
  130.         int   1BH                   ; do an int1B (BIOS break function)
  131.         mov   ax,dosregs+00         ; load the registers from last int21
  132.         mov   bx,dosregs+02
  133.         mov   cx,dosregs+04
  134.         mov   dx,dosregs+06
  135.         mov   es,dosregs+08
  136.         mov   ds,dosregs+10
  137.         int   23H                   ; do an int23 (DOS break function)
  138.  
  139. bomb2:  mov   ax,cs
  140.         mov   ds,ax
  141.         cld
  142.         cli
  143.         les   di,zero               ; restore interrupt vectors
  144.         lea   si,intvec
  145.         mov   cx,s_vector
  146.   rep   movsw
  147.  
  148.         les   di,dword ptr a_bios   ; restore screen stuff
  149.         lea   si,BIOSwss
  150.         mov   cx,size BIOSwss
  151.   rep   movsb
  152.  
  153.         les   di,dword ptr a_break
  154.         mov   al,0
  155.         stosb                       ; clear bios break bit
  156.  
  157.         sti
  158.         mov   al,0                  ; clear the screen
  159.         mov   cx,0
  160.         mov   dx,(24*256)+79
  161.         mov   bh,7
  162.         mov   ah,6
  163.         int   10H
  164.         mov   dx,0                  ; cursor home
  165.         mov   bh,0
  166.         mov   ah,2
  167.         int   10H
  168.         mov   in_prog,0
  169.         mov   ah,4CH                ; end the process
  170.         mov   al,0FFH
  171.         int   21H
  172. bomb    endp
  173.  
  174. int21   proc  far                   ; comes here on int21
  175.         assume cs:cseg,ds:nothing,es:nothing
  176.         cmp   cs:in_prog,0
  177.         jne   int21x
  178.         mov   cs:dosregs+00,ax      ; save the registers
  179.         mov   cs:dosregs+02,bx
  180.         mov   cs:dosregs+04,cx
  181.         mov   cs:dosregs+06,dx
  182.         mov   cs:dosregs+08,es
  183.         mov   cs:dosregs+10,ds
  184. int21x: jmp   dword ptr cs:a_int21
  185. int21   endp
  186.  
  187. makeres proc  near
  188.         assume cs:cseg,ds:cseg,es:nothing
  189.         mov   ax,3509H       ; get vector 09H
  190.         int   21H
  191.         mov   word ptr a_int09,bx
  192.         mov   word ptr a_int09+2,es
  193.  
  194.         mov   ax,2509H       ; set vector 09H
  195.         mov   dx,offset int09
  196.         int   21H
  197.  
  198.         mov   ax,3521H       ; get vector 21H
  199.         int   21H
  200.         mov   word ptr a_int21,bx
  201.         mov   word ptr a_int21+2,es
  202.  
  203.         mov   ax,2521H       ; set vector 21H
  204.         mov   dx,offset int21
  205.         int   21H
  206.  
  207.         in    al,21H         ; save port 21
  208.         mov   port21,al
  209.         in    al,61H         ; save port 61
  210.         mov   port61,al
  211.  
  212.         mov   ax,ds
  213.         mov   es,ax
  214.  
  215.         lds   si,dword ptr cs:a_bios  ; save screen stuff
  216.         lea   di,BIOSwss
  217.         mov   cx,size BIOSwss
  218.    rep  movsb
  219.  
  220.         lds   si,cs:zero     ; save interrupt vectors
  221.         lea   di,intvec
  222.         mov   cx,s_vector
  223.    rep  movsw
  224.  
  225.         mov   ax,3100H       ; ---- terminate and stay resident ----
  226.         mov   dx,offset intvec+s_vector+s_vector
  227.         mov   cl,4
  228.         shr   dx,cl          ; should be able to write (the_end/16+1)
  229.         inc   dx
  230.         int   21H
  231. makeres endp
  232.  
  233. intvec  label word                  ; stores original int vectors here
  234.  
  235. cseg    ends
  236.         end   start
  237.